#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <string.h>

#include "random.h"


// Inicia a funcao rand()
unsigned get_random()
{
    int FD;
    unsigned random;
    FD = open("/dev/random", O_RDONLY);
    read(FD, &random, sizeof(random));
    close(FD);
    return random;
}


// Gera uma palavra com os caracteres gerados de forma aleatoria
// Requer:
//	- string que vai receber a palavra
void str_gen(char *rop_string)
{
    unsigned i, c;
    char lowerCase[] = "abcdefghijklmnopqrstuvwxyz";

    // gera numeros randomicos de 2 a 5
	// unsigned length -> tamanho da palavra a ser gerada
    unsigned length = (unsigned) (rand()%6);
    if(length < 2) length = 2;

	// gera os caracteres de forma aleatoria
    for(i = 0; i < length; i++)
	{
		c =  (unsigned) rand()%26;
        rop_string[i] = lowerCase[c];
    }

    rop_string[i]='\0';
    
    #ifdef DEBUG_R
        printf("DEBUG_R lenght = %d\n", length);
        printf("DEBUG_R : %s\n", rop_string);        
    #endif
}
